package com.dylan.springcloud.feign.service;

import com.dylan.springcloud.feign.config.HelloFeignServiceConfig;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * Created by Dylan on 2018/10/12.
 */
@FeignClient(name = "github-client", url = "https://api.github.com", configuration = HelloFeignServiceConfig.class)
@Service
public interface HelloFeignService {

    @RequestMapping(value = "/search/repositories", method = RequestMethod.GET)
    String searchRepo(@RequestParam("q") String queryStr);

    @RequestMapping(value = "/search/repositories", method = RequestMethod.GET)
    ResponseEntity<byte[]> searchRepoGzip(@RequestParam("q") String queryStr);

    /**
     * 此处设置"Accept-Encoding="，是为了手动删除"Accept-Encoding=gzip,deflate"，这样就不响应压缩后数据了
     */
    @RequestMapping(value = "/search/repositories", method = RequestMethod.GET, headers = {"Accept-Encoding="})
    ResponseEntity<byte[]> searchRepoGzip2(@RequestParam("q") String queryStr);
}
